import { lazy } from "react";
import { AndroidOutlined, AppleOutlined, WindowsOutlined, AliwangwangOutlined, CommentOutlined } from '@ant-design/icons';
import { createBrowserRouter } from "react-router-dom";
const Layout = lazy(() => import('../pages/Layout'));
const Login = lazy(() => import('../pages/Login'));
const NotFound = lazy(() => import('../pages/NotFound'));
const Index = lazy(() => import('../pages/Index'));
const List = lazy(() => import('../pages/List'));
const Message = lazy(() => import('../pages/Message'));
const Order = lazy(() => import('../pages/Order'));
const IndexList = lazy(() => import('../pages/IndexList'))
const IndexCreat = lazy(() => import('../pages/IndexCreat'))
const ArticleDetail = lazy(() => import('../pages/ArticleDetail'))
const Comment = lazy(() => import('../pages/Comment'))
import { type ReactElement } from "react";
// 接口 RouterChildrenListType
interface RouterChildrenListType {
	path: string;
	title: string;
	element: ReactElement;  // 改为 ReactNode
	icon: ReactElement;
	children: []     // 改为 ReactNode
}
// 子路由 
export const RouterChildrenList: RouterChildrenListType[] = [];
let allRouter: any = {
	index: {
		path: '/home',
		title: '首页',
		element: <Index />,
		icon: <AndroidOutlined />,
		children: [
			{
				path: '/home/indexList',
				element: <IndexList />,
				title: '文章列表',
			},
			{
				path: '/home/indexCreat',
				element: <IndexCreat />,
				title: '创建文章',
			},
			{
				path: '/home/articleDetail',
				element: <ArticleDetail />,
				title: '文章详情',
			}
		]
	},
	list: {
		path: '/list',
		title: '列表',
		element: <List />,
		icon: <AppleOutlined />,
	},
	message: {
		path: '/message',
		title: '消息',
		element: <Message />,
		icon: <WindowsOutlined />,

	},
	order: {
		path: '/order',
		title: '订单',
		element: <Order />,
		icon: <AliwangwangOutlined />,
	},
	comment: {
		path: '/comment',
		title: '评论',
		element: <Comment />,
		icon: <CommentOutlined />
	}
};
const role = {
	admin: {
		router: ['index', 'list', 'message', 'order', 'comment']
	},
	user: {
		router: ['index', 'list', 'message', 'comment']
	}
};
const { router } = role[localStorage.getItem('role') === '1' ? 'admin' : 'user'];
router.forEach((item) => {
	RouterChildrenList.push(allRouter[item]);
});
export const RouterList = createBrowserRouter([
	{
		path: '/',
		element: <Layout />,
		children: RouterChildrenList
	},
	{
		path: '/login',
		element: <Login />
	},
	{
		path: '*',
		element: <NotFound />
	}
]);
